#ifndef	BODY_H
#define BODY_H

#include "Game Engine\Header\Physics.h"

class Body : public Physics
{
public:
	Body();
	~Body();

	virtual void			Init( ID3D10Device* device, btDynamicsWorld* world, std::wstring meshFile,
								ID3D10Effect* fx, ID3D10ShaderResourceView* cubeMap, float mass,
								Physics::Shape shape = Cube, bool useShadows = true );

	virtual void			Init( ID3D10Device* device, btDynamicsWorld* world, std::vector<std::wstring> meshFiles,
								ID3D10Effect* fx, ID3D10ShaderResourceView* cubeMap, float mass,
								Physics::Shape shape = Cube, bool useShadows = true );

	virtual D3DXVECTOR3&	GetPosition() = 0;
	virtual D3DXVECTOR3&	GetVelocity() = 0;
	D3DXVECTOR3&			GetConveyorVelocity();

	virtual void			SetPosition( D3DXVECTOR3 pos ) = 0;
	virtual void			SetVelocity( D3DXVECTOR3 vel ) = 0;
	void					SetConveyorVelocity( D3DXVECTOR3 vel );

	void					SetCompoundPosition( UINT base, UINT connection, D3DXVECTOR3 basePos, D3DXVECTOR3 connectionPos );
	void					SetCompoundVelocity( UINT index, D3DXVECTOR3 vel );

	D3DXVECTOR3				GetRotation();
	void					SetRotation( Axis axis, float angle, bool clockwise = true );

	virtual void			Strafe( float d ) = 0;
	virtual void			Walk( float d ) = 0;

	virtual void			Move( float dt ) = 0;
	virtual void			Stop() = 0;

	// If 1.0f is entered, object will bounce as high as it started
	void					SetBounciness( float bounce );

	void					SetGravity( D3DXVECTOR3 gravity );
	void					SetPlayerGravity( float gravity );

	void					SetMass( float mass );

	float					GetWidth( UINT meshIndex = 0 );
	float					GetHeight( UINT meshIndex = 0 );
	float					GetLength( UINT meshIndex = 0 );

	D3DXMATRIX&				GetWorld();

	btRigidBody*			GetRigidBody();

	btPairCachingGhostObject*		GetGhostObject();
	btKinematicCharacterController*	GetCharacter();

	virtual void			Draw( D3DXMATRIX& lightViewProj ) = 0;
	void					DrawToShadowMap( ID3D10EffectMatrixVariable* mfxBuildShadowMapLightWVPVar,
								ID3D10EffectShaderResourceVariable* mfxBuildShadowMapDiffuseMapVar,
								ID3D10EffectPass* pass,	D3DXMATRIX& lightViewProj );

	void					SetLight(const Light& light);
	void					SetEyePos(const D3DXVECTOR3& eyePos);
	void					SetCubeMap(ID3D10ShaderResourceView* cubeMap);
	void					SetShadowMap(ID3D10ShaderResourceView* shadowMap);
	void					EnableCubeMap(bool enable);
	void					UseTangent(bool tangent);
	void					UnbindShadowMap();

protected:
	ID3D10Device*			md3dDevice;

	btDynamicsWorld*		mDynamicsWorld;

	Mesh*					mMesh;
	std::vector<Mesh*>		mMeshVector;

	btCompoundShape*		mCompound;

	btRigidBody*			mBody;

	btPairCachingGhostObject*		mGhostObject;
	btKinematicCharacterController*	mCharacter;

	D3DXVECTOR3				mPosition;
	D3DXVECTOR3				mVelocity;
	D3DXVECTOR3				mConveyorVelocity;

	D3DXMATRIX				mWorld;

	std::vector<float>		mWidth;
	std::vector<float>		mHeight;
	std::vector<float>		mLength;

	float					mMass;
	float					mAngle;
	float					mYaw;
	float					mPitch;
	float					mRoll;
	float					mSpeed;
};

#endif